#!/bin/sh


# path=../

#CONID=zhiliaositemap 
#CONKEY=%212020
#GIT_REPOSITORY=codeup.aliyun.com/zhiliao/zhiliaoketang/zl_news_sitemap.git
GIT_ADDRESS=https://zhiliaositemap:b191849787c9cc3aecdaa831f2d739c0@codeup.aliyun.com/zhiliao/zhiliaoketang/zl_news_sitemap.git

folder=zl_news_sitemap

#如果没有这个文件夹，那么clone
if [ ! -d "$folder" ]; then
  git clone $GIT_ADDRESS

  if [[ "$?" != 0 ]];then
    echo -e "\033[41m git clone fail \033[0m"
  fi

  #第一次没有sitemap仓库，就拉取
  exit 1
fi


echo -e "\033[32m start git \033[0m"

cd $folder

echo -e "\033[32m start pull  \033[0m" 

git pull

if [[ "$?" != 0 ]];then
 echo -e "\033[41m pull fail \033[0m" 
 exit 2
#  cmd /k dir
fi

git status

result=$(git status | grep clean)

if [[ "$result" != "" ]]; then
  echo -e "\033[41m clean fail \033[0m" 
  exit 3
fi

echo -e "\033[32m start add \033[0m"

git add .

echo $?

commit=$(date +"%Y-%m-%d_%H:%M.%S")

git commit -m "$commit"

if [[ "$?" != 0 ]];then
 echo -e "\033[41m commit fail \033[0m" 
 exit 4
fi

git push

if [[ "$?" != 0 ]];then
 echo -e "\033[41m push fail \033[0m"
 exit 5
fi

echo -e "\033[32m push success \033[0m"
exit 0